﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Windows.Controls;
using System.Windows.Input;

namespace HRMSystem
{
    public class ValidateUtility
    {

        public static IList<string> ValidateDoctorLogin(string userName, string password)
        {
            IList<string> errorList = new List<string>();



            return errorList;
        }

        public static IList<string> ValidatePatientLogin(string userName, string password)
        {
            IList<string> errorList = new List<string>();



            return errorList;
        }

        public static string ListToString(IList<string> list)
        {
            string s = "";
            for (int i = 0; i < list.Count; i++)
            {
                if (i == (list.Count - 1))
                    s += list[i];
                else
                    s += list[i] + ", ";
            }

            return s;
        }

        public static bool SetDecimalPoints(object sender, KeyEventArgs e, int decimalPoints)
        {
            if (Keyboard.Modifiers == ModifierKeys.Shift)
            {
                return true;
            }

            if ((e.Key >= Key.D0 && e.Key <= Key.D9 || e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9 || e.Key == Key.Decimal || e.Key == Key.OemPeriod))
            {
                string strkey = e.Key.ToString().Substring(e.Key.ToString().Length - 1, e.Key.ToString().Length - (e.Key.ToString().Length - 1));

                if (e.Key >= Key.D0 && e.Key <= Key.D9 || e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9)
                {
                    TextBox tb = sender as TextBox;
                    int cursorPosLeft = tb.SelectionStart;
                    int cursorPosRight = tb.SelectionStart + tb.SelectionLength;
                    string result1 = tb.Text.Substring(0, cursorPosLeft) + strkey + tb.Text.Substring(cursorPosRight);
                    string[] parts = result1.Split('.');

                    if (parts.Length > 1)
                    {
                        if (parts[1].Length != 1 && (parts[1].Length > decimalPoints || parts.Length > decimalPoints))
                        {
                            return true;
                        }
                    }
                }
                if (((TextBox)sender).Text.Contains(".") && (e.Key == Key.Decimal || e.Key == Key.OemPeriod))
                {
                    return true;
                }
            }
            else
            {
                return true;
            }

            if (e.Key >= Key.A && e.Key <= Key.Z || e.Key == Key.Space)
            {
                return true;
            }

            return false;
        }
    }
}
